package pos.domain;

import java.util.List;

import pos.data.JDBCEntityDAO;

public class EntityStore {

	@SuppressWarnings("unused")
	private List<Entity> entities;
	private static EntityStore entityStore;
	
	public static synchronized EntityStore getInstance() {
		entityStore = new EntityStore();
		
		return entityStore;
	}
	public EntityStore() {
		entities = (new JDBCEntityDAO()).getAllEntities();
	}
	
	public List<Entity> getEntities(){
		//return entities;
		return (new JDBCEntityDAO()).getAllEntities();
	}
	
	public Entity getEntityById(String idEntity){
		return (new JDBCEntityDAO()).getEntityById(idEntity);
	}
	
	public List<Entity> getEntitiesByEvent(Event event){
		return (new JDBCEntityDAO()).getListEntitiesByEvent(event.getId());
	}
	
	public Entity insertEntity(Entity entity, Event event){
		Entity eRes = null;
		eRes = new JDBCEntityDAO().insertEntity(entity, event);
		return eRes;
	}
	
	public void removeEntity(Entity entity){
		// not removed the associations because the objective is to have data
		new JDBCEntityDAO().removeEntity(entity);
	}
	
	public boolean existEntity(Entity entity, Event event){
		return new JDBCEntityDAO().existEntity(entity.getName(),event.getId());
	}
}
